package com.gxa.zhonglong.service.impl;

import com.gxa.zhonglong.common.ExceptionCode;
import com.gxa.zhonglong.exception.BusinessException;
import com.gxa.zhonglong.mapper.StoneFireMapper;
import com.gxa.zhonglong.pojo.StoneFire;
import com.gxa.zhonglong.service.StoneFireService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author NITRO
 */

@Service("stoneFireService")
@Transactional(rollbackFor = {Throwable.class})
public class StoneFireServiceImpl implements StoneFireService {

    @Autowired
    private StoneFireMapper stoneFireMapper;


    @Override
    public Boolean addStoneFire(StoneFire stoneFire) throws BusinessException {
        StoneFire stoneFire1 = stoneFireMapper.selectStoneFireByLevel(stoneFire.getFireLevel());
        if (stoneFire1 == null) {
            stoneFireMapper.addStoneFire(stoneFire);
            return true;
        }
        throw  new BusinessException(ExceptionCode.ADD_DEFEATED);
    }

    @Override
    public void deleteStoneFire(List<Long> ids) throws BusinessException {
        if(stoneFireMapper.deleteStoneFire(ids)<1){
            throw new BusinessException(ExceptionCode.DELETE_FALSE);
        }
    }

    @Override
    public Boolean updateStoneFire(StoneFire stoneFire) throws BusinessException {
        Boolean aBoolean = stoneFireMapper.updateStoneFire(stoneFire);
        if (aBoolean) {
            return true;
        }
        throw  new BusinessException(ExceptionCode.UPDATE_FALSE);
    }

    @Override
    public List<StoneFire> getStoneFireList() {
        List<StoneFire> stoneFires = stoneFireMapper.selectStoneFireList();
        return stoneFires;
    }
}
